package com.hs.biye.model.enums;

import lombok.AllArgsConstructor;
import lombok.Data;

@AllArgsConstructor
public enum GenderEnum {

    MALE("男",1),
    FEMALE("女",0);




    String value;
    Integer code;

    //通过code获取value
    public static String getValueByCode(Integer code) {
        for (GenderEnum genderEnum:GenderEnum.values()){
            if (genderEnum.code.equals(code)){
                return genderEnum.value;
            }
        }
        return "";
    }


    public static Integer getCodeByValue(String value) {
        for (GenderEnum genderEnum:GenderEnum.values()){
            if (genderEnum.value.equals(value)){
                return genderEnum.code;
            }
        }
        return -1;
    }

    /**
     * 判断该值是否在枚举中定义，定义了返回true，未定义返回false
     * @param code
     * @return
     */
    public static boolean isCode(Integer code){
        for (GenderEnum genderEnum:GenderEnum.values()){
            if (genderEnum.code.equals(code)){
                return true;
            }
        }
        return false;
    }

    public String getValue() {
        return value;
    }


    public Integer getCode() {
        return code;
    }

}
